package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevChangeRecordEntity;
import com.sugon.service.DevChangeRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备变更记录Controller
 *
 * @author sugon
 * @date 2019-07-12 08:49:29
 */
@Controller
@RequestMapping("devchangerecord")
public class DevChangeRecordController {
    @Autowired
    private DevChangeRecordService devChangeRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("devchangerecord:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevChangeRecordEntity> devChangeRecordList = devChangeRecordService.queryList(query);
        int total = devChangeRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devChangeRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("devchangerecord:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevChangeRecordEntity devChangeRecord = devChangeRecordService.queryObject(id);

        return R.ok().put("devChangeRecord", devChangeRecord);
    }
    /**
     * 查看信息bydevCode
     */
    @RequestMapping("/getInfoByDevCode/{devCode}")
    @ResponseBody
    public R getInfoByDevCode(@PathVariable("devCode") String devCode) {
        DevChangeRecordEntity devChangeRecord = devChangeRecordService.getInfoByDevCode(devCode);

        return R.ok().put("devChangeRecord", devChangeRecord);
    }

    /**
     * 保存
     */
    @AutoLog("设备变更记录(台账)新增")
    @RequestMapping("/save")
    @RequiresPermissions("devchangerecord:save")
    @ResponseBody
    public R save(@RequestBody DevChangeRecordEntity devChangeRecord) {

        devChangeRecordService.save(devChangeRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("设备变更记录(台账)修改")
    @RequestMapping("/update")
    @RequiresPermissions("devchangerecord:update")
    @ResponseBody
    public R update(@RequestBody DevChangeRecordEntity devChangeRecord) {
        devChangeRecordService.update(devChangeRecord);

        return R.ok();
    }
    /**
     * 修改
     */
    @AutoLog("设备变更记录(台账)修改")
    @RequestMapping("/updateDevChangeRecord")
    @ResponseBody
    public R updateDevChangeRecord(@RequestBody DevChangeRecordEntity devChangeRecord) {
        devChangeRecordService.updateDevChangeRecord(devChangeRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("设备变更记录(台账)删除")
    @RequestMapping("/delete/{ids}")
    @RequiresPermissions("devchangerecord:delete")
    @ResponseBody
    public R delete(@RequestBody String ids) {
        devChangeRecordService.deleteRecord(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevChangeRecordEntity> list = devChangeRecordService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     * 审核
     */
    @AutoLog("设备变更记录(台账)审核")
    @RequestMapping("/review")
    @RequiresPermissions("devchangerecord:review")
    @ResponseBody
    public R review(@RequestBody DevChangeRecordEntity devChangeRecord) {
        devChangeRecordService.review(devChangeRecord);

        return R.ok();
    }

    @AutoLog("设备变更(台账)")
    @RequestMapping("/infoChange")
    @RequiresPermissions("deviceinfo:changeStatus")
    @ResponseBody
    public R infoChange(@RequestBody DevChangeRecordEntity devChangeRecord) {

        devChangeRecordService.infoChange(devChangeRecord);

        return R.ok();
    }
}
